package com.ikdong.toodle.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class ComUtil {
	public static SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	public static String formateDate(Date date,String partten){
		if(partten!=null){
			sd.applyPattern(partten);
		}
		sd.setTimeZone(TimeZone.getTimeZone("GMT+0"));
		return sd.format(date);
	}
	
	public static long parseUnixStamp(Date pDate){
		Timestamp appointTime=Timestamp.valueOf(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(pDate));
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		Date date = new Date();
		try {
			date = df.parse(String.valueOf(appointTime));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		long s=date.getTime();  
		String unixDate=String.valueOf(s).substring(0, 10);
		return Long.valueOf(unixDate);
	}
	
	public static Date parseDateByUS(long timeStamp){
		Long timestamp = timeStamp*1000;  
		return new java.util.Date(timestamp);
	}
}
